﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AMStudio.Common;
using AMStudio.DelegateDispather;
using System.IO;

namespace AMStudio.UserInterface
{
    public partial class ArticlesForm : AWinFormShell
    {
        public ArticlesForm()
        {
            //this.UIName = "Article";
            InitializeComponent();
        }

        private ProductDB db = new Common.ProductDB();
        private ProductSettings currentProduct = new ProductSettings();
        private void ArticlesForm_Load(object sender, EventArgs e)
        {
            //dal.SelectAllMapper();
            base.SubscribeEvent("MANAGER_RET");
            RefreshUI();
        }
        private void RefreshUI()
        {

            this.comboBoxSelectedArticle.Items.Clear();
            binding.Clear();
            foreach (ProductSettings p in db.Products)
            {
                binding.Add(p);
            }
            binding.MoveFirst();
            foreach (string s in db.ProductNames)
            {
                this.comboBoxSelectedArticle.Items.Add(s);
            }
            if (this.comboBoxSelectedArticle.Items.Count > 0)
                this.comboBoxSelectedArticle.SelectedIndex = 0;

            {
                this.comboBoxSt8DispatchPrinter.Items.Clear();
                string directory = @"D:\CanDll";
                if (Directory.Exists(directory))
                {
                    string[] files = Directory.GetFiles(directory, "*.dll");
                    foreach (string f in files)
                    {
                        try
                        {

                            this.comboBoxSt8DispatchPrinter.Items.Add(f);//(f.Replace(directory + @"\", string.Empty));
                        }
                        catch (Exception ex)
                        {
                            //TODO
                        }
                    }
                }
            }

        }

        public override bool ActivateUI()
        {
            this.UIName = this.Name;
            base.ActivateUI();
            db.InitProducts();
            RefreshUI();
            comboBox1.SelectedIndex = 0;
            this.ShowDialog();
            return true;
        }
        protected override void BackGroud_EventHandler(object sender, StationEventArgs e)
        {
            base.BackGroud_EventHandler(sender, e);
            if (e.From == "MANAGER")
            {
                switch (e.Command)
                {
                    case "GET_STATION4_TEACHPANEL":
                        {
                        
                        }
                        break;
                    case "GET_STATION2_TEACHPANEL":
                        {
                            int[] teachPosition = (int[])e.Value;

                            Int32 temp = 0;
                            temp = teachPosition[0] | temp;
                            temp = (teachPosition[1] << 16) | temp;
                            //this.nudSt2CAPPin1PLC.Value = temp;

                            temp = 0;
                            temp = teachPosition[2] | temp;
                            temp = (teachPosition[3] << 16) | temp;
                            //this.nudSt2CAPPin2PLC.Value = temp;
                        }

                        break;
                    case "GET_STATION5_TEACHPANEL":

                        {
                            int[] teachPosition = (int[])e.Value;

                            Int32 temp = 0;
                            temp = teachPosition[0] | temp;
                            temp = (teachPosition[1] << 16) | temp;
                            this.nSt6XPLC.Value = temp;

                            temp = 0;
                            temp = teachPosition[10] | temp;
                            temp = (teachPosition[11] << 16) | temp;
                            this.nSt6YPLC.Value = temp;

                            temp = 0;
                            temp = teachPosition[20] | temp;
                            temp = (teachPosition[21] << 16) | temp;
                            this.nSt6ZPLC.Value = temp;
                        }
                        break;
                    case "GET_STATION5_XYZ":
                        {
                            int[] teachPosition = (int[])e.Value;

                            Int32 temp = 0;
                            temp = teachPosition[20] | temp;
                            temp = (teachPosition[21] << 16) | temp;
                            this.nSt6ZPLC.Value = temp;

                            temp = 0;
                            temp = teachPosition[10] | temp;
                            temp = (teachPosition[11] << 16) | temp;
                            this.nSt6YPLC.Value = temp;

                            temp = 0;
                            temp = teachPosition[0] | temp;
                            temp = (teachPosition[1] << 16) | temp;
                            this.nSt6XPLC.Value = temp;
                        }
                        break;
                    case "GET_STATION4_XYZ":
                        {
                            int[] teachPosition = (int[])e.Value;

                            Int32 temp = 0;
                            temp = teachPosition[0] | temp;
                            temp = (teachPosition[1] << 16) | temp;
                            this.nSt4X.Value = temp;

                            temp = 0;
                            temp = teachPosition[10] | temp;
                            temp = (teachPosition[11] << 16) | temp;
                            this.nSt4Y.Value = temp;

                            temp = 0;
                            temp = teachPosition[20] | temp;
                            temp = (teachPosition[21] << 16) | temp;
                            this.nSt4Z.Value = temp;

                            temp = 0;
                            temp = teachPosition[30] | temp;
                            temp = (teachPosition[31] << 16) | temp;
                            this.nSt4Clamp.Value = temp;
                        }
                        break;
                }
            }
        }

        private void wizard1_FinishButtonClick(object sender, CancelEventArgs e)
        {
            this.timer1.Stop();
            this.timer2.Stop();
            db.SaveOrUpdateProductSettings(currentProduct);
            this.Close();
        }

        private void wizard1_NextButtonClick(object sender, CancelEventArgs e)
        {
            if (wizard1.SelectedPage == PageOverAll)
            {
                bool productExist = db.ProductNames.Exists((s) =>
                {
                    return s == this.comboBoxSelectedArticle.Text;
                });
                if (this.chkCreateArticle.Checked || !productExist)
                {
                    ProductSettings newSettings;
                    newSettings = new ProductSettings();
                    newSettings.Name = this.articleIdentifier.Text;
                    newSettings.Description = this.articleDescription.Text;
                    newSettings.Comments = this.txtAttribute1.Text;
                    newSettings.Remark = this.textBox1.Text;
                    bool alreadyFoundtheProductFromBuffer = false;
                    binding.MoveFirst();
                    for (int i = 0; i < binding.Count; i++)
                    {
                        currentProduct = binding.Current as ProductSettings;
                        if (currentProduct.Name == this.articleIdentifier.Text)
                        {
                            alreadyFoundtheProductFromBuffer = true;
                            break;
                        }
                        else
                        {
                            binding.MoveNext();
                        }
                    }
                    if (!alreadyFoundtheProductFromBuffer)
                    {
                        currentProduct = newSettings;
                        binding.Add(newSettings);
                        binding.MoveNext();
                    }
                } 
                else
                {
                    currentProduct = binding.Current as ProductSettings;
                    currentProduct.Name = this.articleIdentifier.Text;
                }
              
            }
            if (wizard1.SelectedPageIndex == 5)
            {
                comboBox1_SelectedIndexChanged(null, null);
                this.timer1.Interval = 500;
                this.timer1.Start();
            }
            else if (wizard1.SelectedPageIndex == 3)
            {
                this.timer2.Interval = 500;
                this.timer2.Start();
            } 
            else
            {
                this.timer1.Stop();
                this.timer2.Stop();
            }
        }

        private void wizard1_BackButtonClick(object sender, CancelEventArgs e)
        {
            if (wizard1.SelectedPageIndex ==7)
            {
                comboBox1_SelectedIndexChanged(null, null);
                this.timer1.Interval = 500;
                this.timer1.Start();
            }
            else if (wizard1.SelectedPageIndex == 5)
            {
                this.timer2.Interval = 500;
                this.timer2.Start();
            }
            else
            {
                this.timer1.Stop();
                this.timer2.Stop();
            }
        }

        private void wizard1_CancelButtonClick(object sender, CancelEventArgs e)
        {
            this.timer1.Stop();
            this.timer2.Stop();
            this.Close();
        }

        private void comboBoxEx1_SelectedIndexChanged(object sender, EventArgs e)
        {
            binding.MoveFirst();
            for (int i = 0; i < binding.Count; i++)
            {

                currentProduct = binding.List[i] as ProductSettings;//binding.Current as ProductSettings;
                if (currentProduct.Name == this.comboBoxSelectedArticle.Text)
                {
                    break;
                }
                else
                {
                    binding.MoveNext();
                }
            }
            this.articleIdentifier.Text = currentProduct.Name;
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (this.comboBoxSelectedArticle.SelectedIndex >= 0)
            {
                if (WorkorderDB.ExistWorkorderForProduct(this.comboBoxSelectedArticle.Text))
                {
                    System.Windows.Forms.MessageBox.Show("Have related workorder, please delete the workorder first");
                    return;
                }
                if (System.Windows.Forms.MessageBox.Show("Are you sure to delete this product settings", "Information", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    db.Delete(this.comboBoxSelectedArticle.Text);
                    this.RefreshUI();
                }
            }

        }

        private void btnDownLoad_Click(object sender, EventArgs e)
        {
               
        }

        private void btnRefreshStation2_Click(object sender, EventArgs e)
        {
            SendMessage("GET_STATION2_TEACHPANEL", null);
        }

        private void btnReadFromSt2_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == System.Windows.Forms.MessageBox.Show("Are you sure save current teach panel position", "Warning", MessageBoxButtons.YesNo))
            {
                //currentProduct.St2YCAPPin1 = (int)nudSt2CAPPin1PLC.Value;
                //currentProduct.St2YCAPPin2 = (int)nudSt2CAPPin2PLC.Value;

                binding.ResetBindings(false);
            }
        }

        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            SendMessage("GET_STATION3_TEACHPANEL", null);
        }

        private void btnReadFrom_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == System.Windows.Forms.MessageBox.Show("Are you sure save current teach panel position", "Warning", MessageBoxButtons.YesNo))
            {
                //currentProduct.St3YCAPPin1 = (int)nudSt3YCAPPin1PLC.Value;
                //currentProduct.St3YCAPPin2 = (int)nudSt3YCAPPin2PLC.Value;
                //currentProduct.St3YPreCAPPin1 = (int)nudSt3YPreCAPPin1PLC.Value;
                //currentProduct.St3YPreCAPPin2 = (int)nudSt3YPreCAPPin2PLC.Value;
                //currentProduct.St3XCAPPin1 = (int)nudSt3XCAPPin1PLC.Value;
                //currentProduct.St3XCAPPin2 = (int)nudSt3XCAPPin2PLC.Value;
                //currentProduct.St3XPreCAPPin1 = (int)nudSt3XPreCAPPin1PLC.Value;
                //currentProduct.St3XPreCAPPin2 = (int)nudSt3XPreCAPPin2PLC.Value;
                binding.ResetBindings(false);
            }
        }

        private void btnDownLoadStation3_Click(object sender, EventArgs e)
        {
            
            if (System.Windows.Forms.MessageBox.Show("Are you sure to download current axes settings,it will write the configure into PLC", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                //this.nudSt3YCAPPin1PLC.Value = this.nudSt3YCAPPin1PC.Value;
                //this.nudSt3YCAPPin2PLC.Value = this.nudSt3YCAPPin2PC.Value;
                //this.nudSt3YPreCAPPin1PLC.Value = this.nudSt3YPreCAPPin1PC.Value;
                //this.nudSt3YPreCAPPin2PLC.Value = this.nudSt3YPreCAPPin2PC.Value;
                //this.nudSt3XCAPPin1PLC.Value = this.nudSt3XCAPPin1PC.Value;
                //this.nudSt3XCAPPin2PLC.Value = this.nudSt3XCAPPin2PC.Value;
                //this.nudSt3XPreCAPPin1PLC.Value = this.nudSt3XPreCAPPin1PC.Value;
                //this.nudSt3XPreCAPPin2PLC.Value = this.nudSt3XPreCAPPin2PC.Value;

                //SendMessage("WRITE_ST3_PROGRAM", currentProduct.St3SettingsToPLCWords());
            }      
        }

        private void buttonRefreshStation5_Click(object sender, EventArgs e)
        {
            SendMessage("GET_STATION5_TEACHPANEL", null);

        }

        private void buttonReadFrom_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == System.Windows.Forms.MessageBox.Show("Are you sure save current teach panel position", "Warning", MessageBoxButtons.YesNo))
            {
                //currentProduct.St5YPick = (int)nudSt5YPickPLC.Value;
                //currentProduct.St5YCheck = (int)nudSt5YCheckPLC.Value;
                //currentProduct.St5YPutIDC1 = (int)nudSt5YPutIDC1PLC.Value;
                //currentProduct.St5YPutIDC2 = (int)nudSt5YPutIDC2PLC.Value;
                //currentProduct.St5XPick = (int)nudSt5XPickPLC.Value;
                //currentProduct.St5XPutIDC1 = (int)nudSt5XPutIDC1PLC.Value;
                //currentProduct.St5XPutIDC2 = (int)nudSt5XPutIDC2PLC.Value;
                //currentProduct.St5XCheck = (int)nudSt5XCheckPLC.Value;
                //currentProduct.St5CutIDC = (int)nudSt5CutIDCPLC.Value;
                //currentProduct.St5PayIDC = (int)nudSt5PayIDCPLC.Value;
                //currentProduct.St5Pos0 = (int)nudSt5Pos0PLC.Value;
                //currentProduct.St5Pos1 = (int)nudSt5Pos1PLC.Value;
                //currentProduct.St5Pos2 = (int)nudSt5Pos2PLC.Value;
                //currentProduct.St5Pos3 = (int)nudSt5Pos3PLC.Value;

                binding.ResetBindings(false);

            }
        }

        private void btnDownloadStation5_Click(object sender, EventArgs e)
        {
            if (System.Windows.Forms.MessageBox.Show("Are you sure to download current axes settings,it will write the configure into PLC", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {


                //SendMessage("WRITE_ST5_PROGRAM", currentProduct.St5SettingsToPLCWords());
            }     
        }

        private void nudSt5Pos0PC_ValueChanged(object sender, EventArgs e)
        {

        }

        private void nudSt5XPutIDC1PC_ValueChanged(object sender, EventArgs e)
        {

        }

        private void buttonX7_Click(object sender, EventArgs e)
        {
            SendMessage("GET_STATION4_TEACHPANEL", null);
        }

        private void buttonX6_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == System.Windows.Forms.MessageBox.Show("Are you sure save current teach panel position", "Warning", MessageBoxButtons.YesNo))
            {
                currentProduct.St3ClampGrip = (int)nSt4Clamp.Value;
                currentProduct.St3GripX = (int)nSt4X.Value;
                currentProduct.St3GripY = (int)nSt4Y.Value;
                currentProduct.St3GripZ = (int)nSt4Z.Value;
                binding.ResetBindings(false);
            }
        }

        private void buttonX5_Click(object sender, EventArgs e)
        {
            if (System.Windows.Forms.MessageBox.Show("Are you sure to download current axes settings,it will write the configure into PLC", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                SendMessage("WRITE_ST3_PROGRAM", currentProduct.St3SettingsToPLCWords());
            } 
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == System.Windows.Forms.MessageBox.Show("Are you sure save current teach panel position", "Warning", MessageBoxButtons.YesNo))
            {
                nSt6XPC.Value = nSt6XPLC.Value;
                nSt6YPC.Value = nSt6YPLC.Value;
                nSt6ZPC.Value = nSt6ZPLC.Value;

                switch (comboBox1.SelectedIndex)
                {
                    case 0:
                        currentProduct.St5X1 = (int)nSt6XPLC.Value;
                        currentProduct.St5Y1 = (int)nSt6YPLC.Value;
                        currentProduct.St5Z1 = (int)nSt6ZPLC.Value;
                        break;

                    case 1:
                        currentProduct.St5X2 = (int)nSt6XPLC.Value;
                        currentProduct.St5Y2 = (int)nSt6YPLC.Value;
                        currentProduct.St5Z2 = (int)nSt6ZPLC.Value;
                        break;
                        
                    case 2:
                        currentProduct.St5X3 = (int)nSt6XPLC.Value;
                        currentProduct.St5Y3 = (int)nSt6YPLC.Value;
                        currentProduct.St5Z3 = (int)nSt6ZPLC.Value;
                        break;

                    case 3:
                        currentProduct.St5X4 = (int)nSt6XPLC.Value;
                        currentProduct.St5Y4 = (int)nSt6YPLC.Value;
                        currentProduct.St5Z4 = (int)nSt6ZPLC.Value;
                        break;

                    case 4:
                        currentProduct.St5X5 = (int)nSt6XPLC.Value;
                        currentProduct.St5Y5 = (int)nSt6YPLC.Value;
                        currentProduct.St5Z5 = (int)nSt6ZPLC.Value;
                        break;
                }
                binding.ResetBindings(false);
            }
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (System.Windows.Forms.MessageBox.Show("Are you sure to download current axes settings,it will write the configure into PLC", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                switch (comboBox1.SelectedIndex)
                {
                    case 0:
                        currentProduct.St5X1 = nSt6XPC.Value;
                        currentProduct.St5Y1 = nSt6YPC.Value;
                        currentProduct.St5Z1 = nSt6ZPC.Value;
                        break;

                    case 1:
                        currentProduct.St5X2 = nSt6XPC.Value;
                        currentProduct.St5Y2 = nSt6YPC.Value;
                        currentProduct.St5Z2 = nSt6ZPC.Value;
                        break;

                    case 2:
                        currentProduct.St5X3 = nSt6XPC.Value;
                        currentProduct.St5Y3 = nSt6YPC.Value;
                        currentProduct.St5Z3 = nSt6ZPC.Value;
                        break;

                    case 3:
                        currentProduct.St5X4 = nSt6XPC.Value;
                        currentProduct.St5Y4 = nSt6YPC.Value;
                        currentProduct.St5Z4 = nSt6ZPC.Value;
                        break;

                    case 4:
                        currentProduct.St5X5 = nSt6XPC.Value;
                        currentProduct.St5Y5 = nSt6YPC.Value;
                        currentProduct.St5Z5 = nSt6ZPC.Value;
                        break;
                }
                SendMessage("WRITE_ST5_PROGRAM", currentProduct.St5SettingsToPLCWords());
            } 
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            SendMessage("GET_STATION5_XYZ", null);
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            SendMessage("GET_STATION4_XYZ", null);
        }

        private void btnReadLoosenPos_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == System.Windows.Forms.MessageBox.Show("Are you sure save current teach panel position", "Warning", MessageBoxButtons.YesNo))
            {
                currentProduct.St3ClampLoosen = (int)nSt4Clamp.Value;
                currentProduct.St3LoosenX = (int)nSt4X.Value;
                currentProduct.St3LoosenY = (int)nSt4Y.Value;
                currentProduct.St3LoosenZ = (int)nSt4Z.Value;
                binding.ResetBindings(false);
            }
        }


        private void btnClampGo_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22333.2");
        }

        private void btnClampGo_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22333.2");
        }

        private void btnClampBack_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22333.3");
        }

        private void btnClampBack_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22333.3");
        }

        private void btnSt4Xgo_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22330.2");
        }

        private void btnSt4Xgo_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22330.2");
        }

        private void btnSt4Xback_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22330.3");
        }

        private void btnSt4Xback_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22330.3");
        }

        private void btnst4Ygo_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22331.2");
        }

        private void btnst4Ygo_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22331.2");
        }

        private void btnst4Yback_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22331.3");
        }

        private void btnst4Yback_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22331.3");
        }

        private void btnst4Zgo_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22332.2");
        }

        private void btnst4Zgo_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22332.2");
        }

        private void btnst4Zback_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22332.3");
        }

        private void btnst4Zback_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22332.3");
        }

        private void btnXgo_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22530.2");
        }

        private void btnXgo_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22530.2");
        }

        private void btnXback_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22530.3");
        }

        private void btnXback_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22530.3");
        }

        private void btnYgo_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22531.2");
        }

        private void btnYgo_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22531.2");
        }

        private void btnYback_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22531.3");
        }

        private void btnYback_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22531.3");
        }

        private void btnZgo_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22532.2");
        }

        private void btnZgo_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22532.2");
        }

        private void btnZback_MouseDown(object sender, MouseEventArgs e)
        {
            SendMessage("SET_POINT", "E22532.3");
        }

        private void btnZback_MouseUp(object sender, MouseEventArgs e)
        {
            SendMessage("RESET_POINT", "E22532.3");
        }

        private void ArticlesForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.timer1.Stop();
            this.timer2.Stop();
        }

       
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    nSt6XPC.Value = currentProduct.St5X1;
                    nSt6YPC.Value = currentProduct.St5Y1;
                    nSt6ZPC.Value = currentProduct.St5Z1;
                    break;

                case 1:
                    nSt6XPC.Value = currentProduct.St5X2;
                    nSt6YPC.Value = currentProduct.St5Y2;
                    nSt6ZPC.Value = currentProduct.St5Z2;
                    break;

                case 2:
                    nSt6XPC.Value = currentProduct.St5X3;
                    nSt6YPC.Value = currentProduct.St5Y3;
                    nSt6ZPC.Value = currentProduct.St5Z3;
                    break;

                case 3:
                    nSt6XPC.Value = currentProduct.St5X4;
                    nSt6YPC.Value = currentProduct.St5Y4;
                    nSt6ZPC.Value = currentProduct.St5Z4;
                    break;

                case 4:
                    nSt6XPC.Value = currentProduct.St5X5;
                    nSt6YPC.Value = currentProduct.St5Y5;
                    nSt6ZPC.Value = currentProduct.St5Z5;
                    break;
            }
        }

        private void buttonX7_Click_1(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    nSt6XPLC.Value = currentProduct.St5X1;
                    nSt6YPLC.Value = currentProduct.St5Y1;
                    nSt6ZPLC.Value = currentProduct.St5Z1;
                    break;

                case 1:
                    nSt6XPLC.Value = currentProduct.St5X2;
                    nSt6YPLC.Value = currentProduct.St5Y2;
                    nSt6ZPLC.Value = currentProduct.St5Z2;
                    break;

                case 2:
                    nSt6XPLC.Value = currentProduct.St5X3;
                    nSt6YPLC.Value = currentProduct.St5Y3;
                    nSt6ZPLC.Value = currentProduct.St5Z3;
                    break;

                case 3:
                    nSt6XPLC.Value = currentProduct.St5X4;
                    nSt6YPLC.Value = currentProduct.St5Y4;
                    nSt6ZPLC.Value = currentProduct.St5Z4;
                    break;

                case 4:
                    nSt6XPLC.Value = currentProduct.St5X5;
                    nSt6YPLC.Value = currentProduct.St5Y5;
                    nSt6ZPLC.Value = currentProduct.St5Z5;
                    break;
            }
        }
    }
}
